package com.by.service.impl;

import com.by.bean.CInquiry;
import com.by.common.crud.BaseServiceImpl;
import com.by.common.utils.Assert;
import com.by.mapper.CConsultationDetailMapper;
import com.by.mapper.CInquiryDetailMapper;
import com.by.mapper.CInquiryMapper;
import com.by.query.CInquiryQuery;
import com.by.service.CInquiryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class CInquiryServiceImpl extends BaseServiceImpl<CInquiry, CInquiryMapper> implements CInquiryService {
    @Autowired
    CInquiryDetailMapper cInquiryDetailMapper;
    @Autowired
    CConsultationDetailMapper cConsultationDetailMapper;

    @Transactional
    @Override
    public int save(CInquiry entity) {
        int res = super.save(entity);
        Assert.isNotSuccess(res, "保存询价单失败");
        if(null!=entity.getEnquiryDetails()&&entity.getEnquiryDetails().size()>0){
            res=cInquiryDetailMapper.batchSave(entity.getId(),entity.getEnquiryDetails());
            Assert.isNotSuccess(res, "询价明细保存失败");
        }
        if (null!=entity.getConsultDetails())
        {
             res = cConsultationDetailMapper.saveConsult(entity.getId(),entity.getConsultDetails());
            Assert.isNotSuccess(res,"保存咨询明细失败");
        }
        return 1;
    }

}
